/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */
package com.oop.example.data;

import java.io.File;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

/**
 * Hibernate Utility class with a convenient method to get Session Factory
 * object.
 *
 * @author -
 */
public class HibernateUtil {
    
    public static final String url = "hibernate.connection.url";

    private static final SessionFactory sessionFactory;
    private static AnnotationConfiguration cfg;

    static {
        //jdbc:h2:c:\Users\-\Google Диск\Abby\Parser\abbyy.h2.db
        File f = new File("abbyy.h2.db");
        File hcfg = new File("hibernate.cfg.xml");
        try {
            cfg = new AnnotationConfiguration();         
            cfg.setProperty(url, "jdbc:h2:"+f.getAbsolutePath());
            cfg.configure(hcfg);            
            sessionFactory = cfg.buildSessionFactory();
        } catch (Throwable ex) {
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static synchronized SessionFactory getSessionFactory() {
        return sessionFactory;
    }

    public static String getProperty(String name) {
        return cfg.getProperty(name);
        
    }
}
